package ALog;

import static org.junit.Assert.*;
import junit.framework.TestCase;

import org.junit.Test;

public class TestLog extends TestCase {

	public void testConstructor() {
		Date d1 = new Date(1, 6, 2014);
		Date d2 = new Date(2, 5, 2014);
		Date d3 = new Date(3, 5, 2014);

		Entry e1 = new Entry(d1, 5.0, 30, "good");
		Entry e2 = new Entry(d2, 3.0, 20, "tired");
		Entry e3 = new Entry(d3, 4.0, 24, "great");

		ALog a1 = new MTLog();
		ALog a2 = new ConsLog(e1, a1);
		ALog a3 = new ConsLog(e2, a2);
		ALog a4 = new ConsLog(e3, a3);

		System.out.println(a4);

	}

	public void testDistance() {
		Date d1 = new Date(1, 6, 2014);
		Date d2 = new Date(2, 5, 2014);
		Date d3 = new Date(3, 5, 2014);

		Entry e1 = new Entry(d1, 5.0, 30, "good");
		Entry e2 = new Entry(d2, 3.0, 20, "tired");
		Entry e3 = new Entry(d3, 4.0, 24, "great");

		ALog a1 = new MTLog();
		ALog a2 = new ConsLog(e1, a1);
		ALog a3 = new ConsLog(e2, a2);
		ALog a4 = new ConsLog(e3, a3);
		assertEquals(a1.miles(), 0.0);
		assertEquals(a2.miles(), 5.0);
		assertEquals(a3.miles(), 8.0);
		assertEquals(a4.miles(), 12.0);
	}

	public void testGetLog() {
		Date d1 = new Date(1, 6, 2014);
		Date d2 = new Date(2, 5, 2014);
		Date d3 = new Date(3, 5, 2014);

		Entry e1 = new Entry(d1, 5.0, 30, "good");
		Entry e2 = new Entry(d2, 3.0, 20, "tired");
		Entry e3 = new Entry(d3, 4.0, 24, "great");

		ALog a1 = new MTLog();
		ALog a2 = new ConsLog(e1, a1);
		ALog a3 = new ConsLog(e2, a2);
		ALog a4 = new ConsLog(e3, a3);
		assertTrue(a1.getLog(5, 2014).equals(new MTLog()));
		assertTrue(a2.getLog(5, 2014).equals(new MTLog()));
		assertTrue(a3.getLog(5, 2014).equals(new ConsLog(e2, new MTLog())));
		assertTrue(a4.getLog(5, 2014).equals(
				new ConsLog(e3, new ConsLog(e2, new MTLog()))));
	}

	public void testMax() {
		Date d1 = new Date(1, 6, 2014);
		Date d2 = new Date(2, 5, 2014);
		Date d3 = new Date(3, 5, 2014);

		Entry e1 = new Entry(d1, 5.0, 30, "good");
		Entry e2 = new Entry(d2, 3.0, 20, "tired");
		Entry e3 = new Entry(d3, 4.0, 24, "great");

		ALog a1 = new MTLog();
		ALog a2 = new ConsLog(e1, a1);
		ALog a3 = new ConsLog(e2, a2);
		ALog a4 = new ConsLog(e3, a3);
		assertEquals(a1.Max(), 0.0);
		assertEquals(a3.Max(), 5.0);
		assertEquals(a4.Max(), 5.0);
	}
public void testMin(){
	Date d1 = new Date(1, 6, 2014);
	Date d2 = new Date(2, 5, 2014);
	Date d3 = new Date(3, 5, 2014);

	Entry e1 = new Entry(d1, 5.0, 30, "good");
	Entry e2 = new Entry(d2, 3.0, 20, "tired");
	Entry e3 = new Entry(d3, 4.0, 24, "great");

	ALog a1 = new MTLog();
	ALog a2 = new ConsLog(e1, a1);
	ALog a3 = new ConsLog(e2, a2);
	ALog a4 = new ConsLog(e3, a3);
	assertEquals(a1.Min(), 0.0);
	assertEquals(a2.Min(),0.0);
}
	public void testKCCB() {
		Date d1 = new Date(1, 6, 2014);
		Date d2 = new Date(2, 5, 2014);
		Date d3 = new Date(3, 5, 2014);

		Entry e1 = new Entry(d1, 5.0, 30, "good");
		Entry e2 = new Entry(d2, 3.0, 20, "tired");
		Entry e3 = new Entry(d3, 4.0, 24, "great");

		ALog a1 = new MTLog();
		ALog a2 = new ConsLog(e1, a1);
		ALog a3 = new ConsLog(e2, a2);
		ALog a4 = new ConsLog(e3, a3);
		assertEquals(a1.TKCCB(5, 2014), 0.0);
		assertEquals(a2.TKCCB(5, 2014), 0.0);
		assertEquals(a3.TKCCB(5, 2014), 3.0);
		assertEquals(a4.TKCCB(5, 2014), 7.0);

	}
	public void testSortByDistance(){
		Date d1 = new Date(1, 6, 2014);
		Date d2 = new Date(2, 5, 2014);
		Date d3 = new Date(3, 5, 2014);

		Entry e1 = new Entry(d1, 5.0, 30, "good");
		Entry e2 = new Entry(d2, 3.0, 20, "tired");
		Entry e3 = new Entry(d3, 4.0, 24, "great");

		ALog a1 = new MTLog();
		ALog a2 = new ConsLog(e1, a1);
		ALog a3 = new ConsLog(e2, a2);
		ALog a4 = new ConsLog(e3, a3);
		
		assertEquals(a1.sortByDistance(), new MTLog());
		assertEquals(a2.sortByDistance(), new ConsLog(e1,new MTLog()));
		assertEquals(a3.sortByDistance(), new ConsLog(e2, new ConsLog(e1, new MTLog())));
		assertEquals(a4.sortByDistance(), new ConsLog(e2, new ConsLog(e3, new ConsLog(e1, new MTLog()))));
		
	}
}
